import request from '@/utils/request'

export function getWorkflow(id) {
  return request({
    url: `/workflows/${id}`,
    method: 'get'
  })
}

export function deleteWorkflow(id) {
  return request({
    url: `/app/${id}`,
    method: 'DELETE'
  })
}

export function createWorkflow(data) {
  return request({
    url: '/app',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  })
}

export function updatetoolandexecuteWorkflow(id, params) {
  return request({
    url: `/workflows/${id}/execute`,
    method: 'get',
    params
  })
}

export function reflectWorkflow(reflect) {
  return request({
    url: `/workflows/reflect`,
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: reflect
  })
}

export function getMemoryBus() {
  return request({
    url: `/workflows/memory_bus`,
    method: 'GET'
  })
}

export function processOutput(code) {
  return request({
    url: `/workflows/process_output`,
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: code
  })
}

export function saveWorkflowAsApp(workflow) {
  return request({
    url: `/workflows/save_as_app`,
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: workflow
  })
}


export function getTools(params) {
  return request({
    url: `/tools/search`,
    method: 'GET',
    params
  })
}
